
#数据序列化
from rest_framework import serializers
from user_app.models import User

class UserSerializer(serializers.ModelSerializer):
    #定义一下字段验证规则
    #手机号密码必须填
    phone = serializers.CharField(required=True, max_length=11, error_messages={'required': '手机号不能为空', 'invalid': '手机号格式错误'})
    password = serializers.CharField(required=True, max_length=20, error_messages={'required': '密码不能为空', 'invalid': '密码最长不超过20位'})

    class Meta:
        model = User
        #全部返回除了密码
        fields =  ('phone', 'password')
    

